package com.sl.water.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.water.dao.PlanOrgDao;
import com.sl.water.entity.PlanOrg;
import com.sl.water.service.PlanOrgService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: duan
 * @time: 2025-06-27 10:43
 */
@Service
@RequiredArgsConstructor
public class PlanOrgServiceImpl extends ServiceImpl<PlanOrgDao, PlanOrg> implements PlanOrgService {
    @Override
    public Page<PlanOrg> pageList(int page, int size) {
        Page<PlanOrg> orgPage = new Page<>(page, size);
        OrderItem orderItem = new OrderItem();
        orderItem.setAsc(false);
        orderItem.setColumn("created_time");
        orgPage.addOrder(orderItem);
        return this.page(orgPage);
    }

    @Override
    public List<PlanOrg> listByName(String name) {
        LambdaQueryWrapper<PlanOrg> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNoneEmpty(name)) {
            queryWrapper.eq(PlanOrg::getName, name);
        }
        return this.list(queryWrapper);
    }
}
